﻿using AnesSystem.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnesSystem.Controls
{
    /// <summary>
    /// TWCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class TWCtrl : RealVitalIcon
    {
        public TWCtrl()
        {
            InitializeComponent();
            DefaultColor= new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF2AACE8"));
            ResizeIcon();
        }
        public override void ResizeIcon()
        {
            Brush color = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FF2AACE8"));
            Line line1 = new Line();
            line1.X1 = 0;
            line1.Y1 = this.Height/2;

            line1.X2 = this.Width / 2;
            line1.Y2 = this.Height;
            line1.Stroke = color;
            line1.StrokeThickness = 2;
            _grid.Children.Add(line1);

            Line line2 = new Line();
            line2.X1 = this.Width/2;
            line2.Y1 = this.Height;

            line2.X2 = this.Width ;
            line2.Y2 = this.Height/2;
            line2.Stroke = color;
            line2.StrokeThickness = 2;
            _grid.Children.Add(line2);

            Line line3 = new Line();
            line3.X1 = this.Width;
            line3.Y1 = this.Height/2;

            line3.X2 = this.Width/2;
            line3.Y2 = 0;
            line3.Stroke = color;
            line3.StrokeThickness = 2;
            _grid.Children.Add(line3);

            Line line4 = new Line();
            line4.X1 = this.Width / 2;
            line4.Y1 = 0;

            line4.X2 = 0;
            line4.Y2 = this.Height / 2;
            line4.Stroke = color;
            line4.StrokeThickness = 2;
            _grid.Children.Add(line4);
        }
        protected override int CalValue2Yplot(PatientVitalSignsModel iItem)
        {
            if (string.IsNullOrEmpty(iItem.ModValue)) return 0;
            double value = Convert.ToDouble(iItem.ModValue);
            double lineHeight = LocationUtil.RealTimeSignItem_TotalRows * LocationUtil.RealTimeSignItem_Height;
            return CheckValue2Yplot( Convert.ToInt32(lineHeight -  (value-LocationUtil.TwStart_Value)/LocationUtil.TwSpan_Value*LocationUtil.RealTimeSignItem_Height - this.Height/2));
        }
        public override double CalY2Valueplot(double top)
        {
            double lineHeight = LocationUtil.RealTimeSignItem_TotalRows * LocationUtil.RealTimeSignItem_Height;
            return CheckY2Valueplot( Math.Round(Convert.ToDouble((lineHeight - top) / LocationUtil.RealTimeSignItem_Height * LocationUtil.TwSpan_Value + LocationUtil.TwStart_Value),1));
        }
        public override double CheckY2Valueplot(double value)
        {
            if (value < 22)
            {
                return 22;
            }
            else if (value > 44)
            {
                return 44;
            }
            else
            {
                return value;
            }
        }
        public override int CheckValue2Yplot(int y)
        {
            if (y < 0)
            {
                return 0;
            }
            else if (y > LocationUtil.RealTimeSignItem_Height * LocationUtil.RealTimeSignItem_TotalRows)
            {
                return LocationUtil.RealTimeSignItem_Height * LocationUtil.RealTimeSignItem_TotalRows;
            }
            else
            {
                return y;
            }
        }
    }
}
